using System;
using System.ComponentModel;

using DevExpress.Xpo;
using DevExpress.Data.Filtering;

using DevExpress.ExpressApp;
using DevExpress.Persistent.Base;
using DevExpress.Persistent.BaseImpl;
using DevExpress.Persistent.Validation;
using DevExpress.ExpressApp.Security;
using DevExpress.ExpressApp.Security.Strategy;

namespace WaTP.Module.BusinessObjects
{
    [DefaultClassOptions]
    public class CustomsFormality : BaseObject
    {
        public CustomsFormality(Session session)
            : base(session)
        {
            // This constructor is used when an object is loaded from a persistent storage.
            // Do not place any code here or place it only when the IsLoading property is false:
            // if (!IsLoading){
            //    It is now OK to place your initialization code here.
            // }
            // or as an alternative, move your initialization code into the AfterConstruction method.
        }
        private string subject;
        [RuleRequiredField(DefaultContexts.Save)]
        public string Subject {
            get { return subject; }
            set { SetPropertyValue("Subject", ref subject, value); }
        }

        private DateTime startDateTime;
        public DateTime StartDateTime {
            get { return startDateTime; }
            set { SetPropertyValue("StartDateTime", ref startDateTime, value); }
        }
        private DateTime endDateTime;
        public DateTime EndDateTime {
            get { return endDateTime; }
            set { SetPropertyValue("EndDateTime", ref endDateTime, value); }
        }
        private float weightTotal;
        public float WeightTotal {
            get { return weightTotal; }
            set { SetPropertyValue("WeightTotal", ref weightTotal, value); }
        }
        private string description;
        public string Description {
            get { return description; }
            set { SetPropertyValue("Description", ref description, value); }
        }
        private FormalityStatus status;
        public FormalityStatus Status {
            get { return status; }
            set { SetPropertyValue("Status", ref status, value); }
        }
        //User.
        [Persistent("User")]
        private SecuritySystemUser user;
        [PersistentAlias("user")]
        public SecuritySystemUser User
        {
            get { return user; }
            internal set { user = value; }
        }
        //Formality-Documents
        [Association("Formality-Documents"), Aggregated]
        public XPCollection<Document> Documents {
            get { return GetCollection<Document>("Documents");}
        }
        [Association("Formality-Activities"), Aggregated]   
        public XPCollection<Activity> Activities{
            get { return GetCollection<Activity>("Activities");}
        }

        private Contract contract;
        [Association("Contract-Formalities")]
        public Contract Contract {
            get { return contract; }
            set { SetPropertyValue("Contract", ref contract, value); }
        }
        public override void AfterConstruction()
        {
            base.AfterConstruction();
            // Place here your initialization code.
            status = FormalityStatus.Inprogress;
            user = Session.GetObjectByKey<SecuritySystemUser>(SecuritySystem.CurrentUserId);
        }
    }

    public enum FormalityStatus {
        [ImageName("State_Task_InProgress")]
        Inprogress,
        [ImageName("State_Task_Completed")]
        Completed
    }
}
